package demo1.x.com;

import com.opensymphony.xwork2.ActionSupport;
import demo1.x.com.utils.Demo1Tool;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by sanmao on 2017/6/12.
 */
public class Demo1Action extends ActionSupport{
    private String gotoUrl;

    public String getGotoUrl() {
        return gotoUrl;
    }

    public void setGotoUrl(String gotoUrl) {
        this.gotoUrl = gotoUrl;
    }

    public String main(){
        HttpServletRequest request= ServletActionContext.getRequest();
        Cookie[] cookies=request.getCookies();
        if(cookies!=null){
            for(Cookie cookie:cookies){
                if(cookie.equals("ssohxw")){
                    String result= Demo1Tool.doGet("http://check.x.com/sso/checkCookies",cookie.getName(),cookie.getValue());
                    if(result.equals("1")){
                        return SUCCESS;
                    }
                }
            }
        }

        gotoUrl="192.168.1:8080//demo1.x.com/demo1/action.action";
        return LOGIN;
    }
}
